package com.itsenpupulai.bdtest.activity;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.SystemClock;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.itsenpupulai.bdtest.R;
import com.itsenpupulai.bdtest.Receiver.UpdateReceiver;
import com.itsenpupulai.bdtest.utils.AlarmUtil;

public class AlarmManagerActivity extends AppCompatActivity {

    public AlarmManager alarmManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_alarm_manager);

        alarmManager = AlarmUtil.getAlarmManager(this);
    }

    public void sendUpdataBroadcastRepeat(){
        Intent intent = new Intent(this, UpdateReceiver.class);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
        //开始时间
         long firstime= SystemClock.elapsedRealtime();
         AlarmManager am = (AlarmManager) this.getSystemService(ALARM_SERVICE);
        // 60秒一个周期，不停的发送广播
         am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, firstime, 60*1000, pendingIntent);
    }
}
